﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;

namespace NSATBPortal
{
    public partial class TestSetEditOrder : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            string sVal = Server.UrlDecode(Request.QueryString["Name"].ToString());
            lblParent.Text = "Ordering for " + sVal;

        }

        protected void DefTestSetGrid_RowEditing(object sender, GridViewEditEventArgs e)
        {
            e.Cancel = true;

            int iIndex = e.NewEditIndex;
            string sRecID = DefTestSetGrid.DataKeys[iIndex].Value.ToString();

            using (ATBSchemaDB objATBDB = new ATBSchemaDB())
            {
                objATBDB.DefTestSetOrderMoveUp(int.Parse(sRecID));
            }
            DefTestSetGrid_LoadTable();
        }
        protected void DefTestSetGrid_Init(object sender, EventArgs e)
        {
            DefTestSetGrid_LoadTable();
        }
        private void DefTestSetGrid_LoadTable()
        {
            string sVal = Request.QueryString["ID"].ToString();
            int iId = Convert.ToInt32(sVal);

            DataTable dtResults;
            using (ATBSchemaDB objATBDB = new ATBSchemaDB())
            {
                dtResults = objATBDB.GetDefTestSetOrdering(iId);
            }

            DefTestSetGrid.DataSource = dtResults;
            DefTestSetGrid.DataBind();
        }
        protected void DefTestSetGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            e.Cancel = true;

            int iIndex = e.RowIndex;
            string sRecID = DefTestSetGrid.DataKeys[iIndex].Value.ToString();
            using (ATBSchemaDB objATBDB = new ATBSchemaDB())
            {
                objATBDB.DefTestSetOrderMoveDown(int.Parse(sRecID));
            }
            DefTestSetGrid_LoadTable();
        }

        protected void DefTestSetGrid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int iIndex = Convert.ToInt32(e.CommandArgument);
            string sRecID = DefTestSetGrid.DataKeys[iIndex].Value.ToString();
            if (e.CommandName == "Select")
            {
                string sVal = Request.QueryString["ID"].ToString();

                Response.Redirect("TestSetEditDataSet.aspx?ID=" + sRecID.Trim() 
                        + "&ParentID=" + Request.QueryString["ID"].ToString()
                        + "&ParentName=" + Request.QueryString["Name"].ToString());
                e.Handled = true;
                return;
            }
        }

    }
}